package com.business.controller.interfaced;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.business.service.interfaced.impl.HeadlinesInService;
import com.system.controller.base.BaseController;
import com.system.util.AppUtil;
import com.system.util.PageData;
import com.system.util.RelativeDateFormat;
import com.system.util.Tools;
import com.system.util.ToolsUtil;





/**
 * 头条接口
 * @Function 
 * @Author zhaozhenhua
 * @Date 2018年4月9日
 */
@Controller
@RequestMapping(value="/appheadlinesin")
public class HeadlinesInController extends BaseController {
	
	@Resource(name="headlinesInService")
	private HeadlinesInService headlinesInService;
	
	
	/**
	 * 获取所有的菜单项
	  * @Description
	  * @Author zhaozhenhua
	  * @date   2018年4月9日
	  * @param pd
	  * @return
	  * @throws Exception
	 */
	@RequestMapping(value="/caidanlist")
	@ResponseBody
	public Object caidanlist(){
		logBefore(logger, "获取所有的菜单项");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("CAIDANLIST", pd.getString("FKEY"))){	//检验请求key值是否合法
			 List<PageData> list = headlinesInService.getCaiDanList(pd);
			 if(list!=null&&list.size()>0){
				 map.put("list", list);
			 }
			 result = (list==null||list.size()<=0) ?  "02" :  "01";
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	/**
	 * 根据菜单ID获取头条信息列表
	  * @Description
	  * @Author zhaozhenhua
	  * @date   2018年4月9日
	  * @param pd
	  * @return
	  * @throws Exception
	 */
	@RequestMapping(value="/getheadlines")
	@ResponseBody
	public Object getHeadlinesById(){
		logBefore(logger, "据菜单ID获取头条信息列表");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("GETHEADLINES", pd.getString("FKEY"))){	//检验请求key值是否合法
					List<PageData> list = headlinesInService.getHeadlinesById(pd);
					 if(list!=null&&list.size()>0){
						 for (PageData data : list) {
							 ToolsUtil.putImgstoArray(data, "SHOWIMAGE");
							 //对时间进行格式化
							 String ADD_TIME = RelativeDateFormat.format(data.getString("ADD_TIME"));
							 data.put("ADD_TIME", ADD_TIME);
						 }
						 map.put("list", list);
					 }
				result = (list==null||list.size()<=0) ?  "02" :  "01";
			}else{
				result = "05";
			}	
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	
}


